﻿Imports System.Windows.Forms
Imports BUS

Public Class Main

    Private _daDangNhap As Boolean = False



    Public Property DaDangNhap() As Boolean
        Get
            Return _daDangNhap
        End Get
        Set(ByVal value As Boolean)
            _daDangNhap = value
        End Set
    End Property

    Public Sub DangNhap()
        _daDangNhap = True
        EditingStatusLabel.Text = "Có thể chỉnh sửa Cơ Sở Dữ liệu."
    End Sub

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs)
        ' Create a new instance of the child form.
        Dim ChildForm As New System.Windows.Forms.Form
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        ChildForm.Text = "Window " & m_ChildFormNumber

        ChildForm.Show()
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs)
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = OpenFileDialog.FileName
            ' TODO: Add code here to open the file.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
    End Sub



    'Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
    '    Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    'End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub PrintToolStripButton_Click(sender As System.Object, e As System.EventArgs)
        Dim frmTuVanHeThongDienNLMT As New frmTuVanHeThongDienNLMT()
        frmTuVanHeThongDienNLMT.MdiParent = Me
        frmTuVanHeThongDienNLMT.Show()
    End Sub

    Private Sub PinToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PinToolStripMenuItem.Click
        Dim frmLuuPin As New frmLuuPinNLMT()
        frmLuuPin.TrangThai(DaDangNhap)
        frmLuuPin.MdiParent = Me
        frmLuuPin.Show()
    End Sub


    Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim hoster = DataProviderBUS.HostKetNoi()
        If hoster = "#" Then
            MessageBox.Show("Chưa có kết nối tới máy chủ. Xin kiểm tra lại trong phần cài đặt.")
            Dim frmCaiDat As New frmCaiDat()
            frmCaiDat.MdiParent = Me
            frmCaiDat.Show()
            frmCaiDat.TabPageKetNoi.Focus()
            Return
        Else
            Dim testconnection = DataProviderBUS.TestConnection()
            If testconnection = False Then
                MessageBox.Show("Kết nối với máy chưa CSDL thất bại. Xin vui lòng kiểm tra lại tình trạng máy chủ hoặc Tên Máy Chủ trong phần cài đặt.")
                Dim frmCaiDat As New frmCaiDat()
                frmCaiDat.MdiParent = Me
                frmCaiDat.Show()
                frmCaiDat.TabPageKetNoi.Focus()
                Return
            End If
        End If
        frmTuVanHeThongDienNLMT.MdiParent = Me
        frmTuVanHeThongDienNLMT.Show()

    End Sub
    
    Private Sub LoạiPinToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LoạiPinToolStripMenuItem.Click
        Dim frmLoaiPin As New frmLoaiPin()
        frmLoaiPin.TrangThai(DaDangNhap)
        frmLoaiPin.MdiParent = Me
        frmLoaiPin.Show()
    End Sub

    Private Sub MạchĐiềuKhiểnToolStripMenuItem2_Click(sender As System.Object, e As System.EventArgs) Handles MạchĐiềuKhiểnToolStripMenuItem2.Click
        Dim frmMDK As New frmLuuMachDieuKhien()
        frmMDK.TrangThai(DaDangNhap)
        frmMDK.MdiParent = Me
        frmMDK.Show()
    End Sub

    Private Sub LoạiMạchToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LoạiMạchToolStripMenuItem.Click
        Dim frmLoaiMDK As New frmLoaiMachDieuKhien()
        frmLoaiMDK.TrangThai(DaDangNhap)
        frmLoaiMDK.MdiParent = Me
        frmLoaiMDK.Show()
    End Sub


    Private Sub ÁcquyToolStripMenuItem3_Click(sender As System.Object, e As System.EventArgs) Handles ÁcquyToolStripMenuItem3.Click
        Dim frmAcquy As New frmLuuAcquy()
        frmAcquy.TrangThai(DaDangNhap)
        frmAcquy.MdiParent = Me
        frmAcquy.Show()
    End Sub

    Private Sub LoạiÁcquyToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LoạiÁcquyToolStripMenuItem.Click
        Dim frmLoaiAcquy As New frmLoaiAcQuy()
        frmLoaiAcquy.TrangThai(DaDangNhap)
        frmLoaiAcquy.MdiParent = Me
        frmLoaiAcquy.Show()
    End Sub

    Private Sub BộKíchĐiệnToolStripMenuItem4_Click(sender As System.Object, e As System.EventArgs) Handles BộKíchĐiệnToolStripMenuItem4.Click
        Dim frmBKD As New frmLuuBoKichDien()
        frmBKD.TrangThai(DaDangNhap)
        frmBKD.MdiParent = Me
        frmBKD.Show()
    End Sub

    Private Sub LoạiBộKíchĐiệnToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LoạiBộKíchĐiệnToolStripMenuItem.Click
        Dim frmLoaiBKD As New frmBoKichDien()
        frmLoaiBKD.TrangThai(DaDangNhap)
        frmLoaiBKD.MdiParent = Me
        frmLoaiBKD.Show()
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
        Dim frmTraCuuPin As New frmTraCuuPin()
        frmTraCuuPin.MdiParent = Me
        frmTraCuuPin.Show()

    End Sub

    Private Sub MạchĐiềuKhiểnToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles MạchĐiềuKhiểnToolStripMenuItem1.Click
        Dim frmTraCuuMDK As New frmTraCuuMachDieuKhien()
        frmTraCuuMDK.MdiParent = Me
        frmTraCuuMDK.Show()

    End Sub

    Private Sub ÁcquyToolStripMenuItem2_Click(sender As System.Object, e As System.EventArgs) Handles ÁcquyToolStripMenuItem2.Click
        Dim frmTraCuuAcquy As New frmTraCuuAcQuy()
        frmTraCuuAcquy.MdiParent = Me
        frmTraCuuAcquy.Show()

    End Sub

    Private Sub BộKíchĐiệnToolStripMenuItem3_Click(sender As System.Object, e As System.EventArgs) Handles BộKíchĐiệnToolStripMenuItem3.Click
        Dim frmTraCuuBKD As New frmTraCuuBoKichDien()
        frmTraCuuBKD.MdiParent = Me
        frmTraCuuBKD.Show()

    End Sub

    Private Sub MậtKhẩuToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MậtKhẩuToolStripMenuItem.Click
        Dim frmCaiDat As New frmCaiDat()
        frmCaiDat.MdiParent = Me
        frmCaiDat.Show()
    End Sub

    Private Sub ĐăngNhậpToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ĐăngNhậpToolStripMenuItem.Click
        Dim DN As New NhapMatKhau()
        DN.FormCha()
        DN.MdiParent = Me
        DN.Show()
    End Sub

    Private Sub TưVấnHệThốngĐiệnNLMTToolStripMenuItem_Click_1(sender As System.Object, e As System.EventArgs) Handles TưVấnHệThốngĐiệnNLMTToolStripMenuItem.Click
        Dim frmTuVanHeThongDienNLMT As New frmTuVanHeThongDienNLMT()
        frmTuVanHeThongDienNLMT.MdiParent = Me
        frmTuVanHeThongDienNLMT.Show()
    End Sub
End Class
